{include file="public/head"/}
<div class="container-fluid">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="alert alert-dismissable alert-info" id="headeralert">
                <button type="button" class="close">×</button>
                <p></p>
            </div>
        </div>
    </div>
    <div class="ntDesktop">
        <div class="ntDesktop-head">仓库列表</div>
        <div class="col-md-12 text-right">
            <div>
                {in name="273" value="$Think.session.admin.auth_ids"}
                <a href="/admin/warehouses/setingadd" class="btn btn-primary" data-toggle="modal"
                   data-target="#warehouse_editModal" stytle="margin-right:20px"><span
                        class="glyphicon glyphicon-plus"></span> 添加新仓库</a>
                {/in}
            </div>
        </div>


        <div class="row clearfix">
            <div class="col-md-12 column">
                <table class="table table-striped table-hover ntTable">
                    <thead>
                    <tr>
                        <th> 名称</th>
                        <th> 地区</th>
                        <th class="sorting" @click="sortfun(1)" data-order="1"> 编辑</th>
                        <th> 操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="item in list" :key="item.id" v-if="list.length>0">
                        <td><a :href="'/admin/warehouses/warehousedetail?id='+item.id">{{item.name}}</a></td>
                        <td> {{item.addressname}}</td>
                        <td> {{item.updatename}} <br/>
                            <small>{{item.update_date}}</small>
                        </td>
                        <td class="text-right">
                            <div>
                                {in name="276" value="$Think.session.admin.auth_ids"}
                                <a :href="'/admin/warehouses/warehousedetail?id='+item.id" @click="gotoseting" class="btn btn-sm btn-default">查看</a>
                                {/in}

                                {in name="277" value="$Think.session.admin.auth_ids"}
                                <a :href="'/admin/warehouses/warseadmin?id='+item.id" class="btn btn-sm btn-primary"
                                   data-toggle="modal"
                                   data-target="#warehouse_adminModal"><span class="fa fa-users"></span> 人员</a>
                                {/in}

                                {in name="274" value="$Think.session.admin.auth_ids"}
                                <a :href="'/admin/warehouses/setingedit?id='+item.id" class="btn btn-sm btn-primary"
                                   data-toggle="modal" data-target="#warehouse_editModal"> <span
                                        class="glyphicon glyphicon-pencil"></span> 编辑</a>
                                {/in}

                                {in name="278" value="$Think.session.admin.auth_ids"}
                                <a :href="'/admin/warehouses/setingplace?id='+item.id" class="btn btn-sm btn-primary"
                                   data-toggle="modal" data-target="#place_editModal"> <span
                                        class="fa fa-calculator"></span>位置</a>
                                {/in}

                                {in name="279" value="$Think.session.admin.auth_ids"}
                                <a :href="'/admin/warehouses/setingarea?id='+item.id" class="btn btn-sm btn-primary"
                                   data-toggle="modal" data-target="#area_editModal">
                                    <span class="fa fa-columns"></span>区域
                                </a>
                                {/in}

                                {in name="280" value="$Think.session.admin.auth_ids"}
                                <a :href="'/admin/warehouses/setingroot?id='+item.id" class="btn btn-sm btn-primary"
                                   data-toggle="modal" data-target="#distance_editModal"><span
                                        class="fa fa-code-branch"></span> 距离</a>
                                {/in}

                                {in name="275" value="$Think.session.admin.auth_ids"}
                                <a href="#" @click.prevent="delseting(item.id,item.name)"
                                   class="btn btn-sm btn-default option-del"><span
                                        class="glyphicon glyphicon-trash"></span>删除</a>
                                {/in}
                            </div>
                        </td>
                    </tr>
                    <tr style="text-align: center;" v-if="list.length==0">
                        <td colspan="5" class="no_date">{:lang('no_data')}</td>
                    </tr>
                    </tbody>
                </table>
                <ul class="pagination" id="pagination" v-show="list.length!=0">
                </ul>
            </div>
        </div>
    </div>
</div>
<!--仓库的人员设置-->
<div class="modal fade" id="warehouse_adminModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg" style="width:60%">
        <div class="modal-content">

        </div>
    </div>
</div>
<div class="modal fade" id="warehouse_editModal" tabindex="-1" role="dialog" aria-labelledby="ntModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg" style="width:60%">
        <div class="modal-content">

        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!--设置仓库之前的距离-->
<div class="modal fade" id="distance_editModal" tabindex="-1" role="dialog" aria-labelledby="ntModalLabel2"
     aria-hidden="true">
    <div class="modal-dialog modal-lg" style="width:60%">
        <div class="modal-content">

        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!--设置里的位置-->

<div class="modal fade" id="place_editModal" tabindex="-1" role="dialog" aria-labelledby="ntModalLabel2"
     aria-hidden="true">
    <div class="modal-dialog modal-lg" style="width:60%">
        <div class="modal-content">

        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!--设置里的区域-->

<div class="modal fade" id="area_editModal" tabindex="-1" role="dialog" aria-labelledby="ntModalLabel3"
     aria-hidden="true">
    <div class="modal-dialog modal-lg" style="width:60%">
        <div class="modal-content">

        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!--弹窗部分 结束-->
{include file="public/foot"/}
<script>
    var table = new Vue({
        el: '.ntDesktop',
        data: {
            list: [],
            page: 1,
            pageSize: 30,
            order: 1,
            pauname: '',
        },
        methods: {
            setPage(pageCurrent, pageSum) {
                //数据总条数
                var myPageCount = pageSum;
                //一页显示多少条
                var myPageSize = this.pageSize;
                //总页数
                var countindex = myPageCount % myPageSize > 0 ? (myPageCount / myPageSize) + 1 : (myPageCount / myPageSize);
                $.jqPaginator('#pagination', {
                    totalPages: parseInt(countindex),
                    //最多显示多少页
                    visiblePages: 5,
                    //默认显示第几页
                    currentPage: pageCurrent,
                    first: '<li class="first"><a href="javascript:;">' + langcon.page_home + '</a></li>',
                    prev: '<li class="prev"><a href="javascript:;"><i class="arrow arrow2"></i>' + langcon.previous_page + '</a></li>',
                    next: '<li class="next"><a href="javascript:;">' + langcon.next_page + '<i class="arrow arrow3"></i></a></li>',
                    last: '<li class="last"><a href="javascript:;">' + langcon.last_page + '</a></li>',
                    page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
                    all: '<li class="page"><a href="javascript:;">' + myPageCount + ' / ' + this.page + 'PG , ' + this.pageSize + ' /PG</a></li>',
                    onPageChange: (num, type) => {
                        if (type == "change") {
                            this.page = num
                            this.getAllList()
                        }
                    }
                });
            },
            //数据所有获取
            getAllList(){
                $('.loding').show()
                $.ajax({
                    url: "/admin/warehouses/seting",
                    type: 'post',
                    data: {
                        page: this.page,//分页
                        pageSize: this.pageSize,//条数
                    },
                    dataType: "json",
                    success: (result) => {
                        this.list = result.getsetings;
                        if (result.size)
                            this.setPage(parseInt(this.page), result.size)
                        $('.loding').hide()
                    }
                })
            },
            sortfun(type, $event){  //排序
                this.order = $(event.target).attr('data-order')
                if (type == 1) {
                    this.pauname = 'update_at'
                    this.list.sort(this.sortoneData);
                }
            },
            sortoneData(a, b) {
                if (this.order == 1) {
                    $(event.target).attr('data-order', 2)
                    return b.update_at - a.update_at
                } else {
                    $(event.target).attr('data-order', 1)
                    return a.update_at - b.update_at
                }
            },
            delseting(id, name){
                $.ajax({
                    url: '/admin/warehouses/setingdel',
                    data: {
                        id,
                        name
                    },
                    type: 'post',
                    success: (res) => {
                        res = JSON.parse(res)
                        change_mes_type('#headeralert', res.status)
                        $('#headeralert').show()
                        $('#headeralert p').html('*' + res.msg + '<br>')
                        if (res.status == 1) {
                            if (!(this.list.length - 1)) {
                                if (this.page > 1) {
                                    this.page--
                                }
                            }
                            this.getAllList()
                        }
                    }
                })
            },
            //分页存储
            gotoseting(){
                var storage=window.localStorage;
                storage.setItem('pageseting',this.page);//分页
            }
        },
        created(){
            var storage=window.localStorage;
            if($('#formMenu').text() != 1){
                //返回列表
                if(storage.getItem('pageseting')){
                    this.page= storage.getItem("pageseting");
                }
            }
            storage.removeItem("pageseting");
            this.getAllList()
            $('#warehouse_editModal').on('hide.bs.modal', () => {
                if (localStorage.getItem("model")) {
                    this.getAllList();
                    localStorage.removeItem("model");
                }
            })
            $('#warehouse_adminModal').on('hide.bs.modal', () => {
                if (localStorage.getItem("model")) {
                    this.getAllList();
                    localStorage.removeItem("model");
                }
            })
        }
    })
    //替换之前的模板
    $("#warehouse_editModal").on("hidden.bs.modal", function () {
        $(this).removeData("bs.modal");
        $(".modal-content").children().remove();
        $(document).unbind('keydown')
    });
    $("#distance_editModal").on("hidden.bs.modal", function () {
        $(this).removeData("bs.modal");
        $(".modal-content").children().remove();
        $(document).unbind('keydown')
    });
    $("#place_editModal").on("hidden.bs.modal", function () {
        $(this).removeData("bs.modal");
        $(".modal-content").children().remove();
        $(document).unbind('keydown')
    });
    $("#area_editModal").on("hidden.bs.modal", function () {
        $(this).removeData("bs.modal");
        $(".modal-content").children().remove();
        $(document).unbind('keydown')
    });
    $("#warehouse_adminModal").on("hidden.bs.modal", function () {
        $(this).removeData("bs.modal");
        $(".modal-content").children().remove();
        $(document).unbind('keydown')
    });
</script>


